from Utilities.AutoGetOperator.selectPackage import get_func
Operator=get_func(r'Operators/OWAOperator/Operator.py','Operator')

import numpy as np
class OWAS(Operator):
    """
    OWAS:适用于矩阵求解加权平均
    """
    def getResult(self):
        # 获取随机整数矩阵
        matrix = np.random.randint(300, 400, (6, 6))  # 随机生成（300，400）的整数，6x6的矩阵
        weight = self.weight_list
        n = len(matrix)
        m = len(matrix[0])
        # 首先对矩阵的每一行进行求加权平均，并存放入一个数组中
        Mat = []
        for i in range(n):
            sum = 0
            for j in range(m):
                sum += matrix[i][j] * weight[j]
            Mat.append(sum)

        # 再对这一组数进行OWA计算
        # 对Mat进行升序排列
        Mat = self.asc(Mat)
        # 获取初始值
        res = Mat[0] * weight[0]
        for i in range(1,len(Mat)):
            res += Mat[i] * weight[i]

        return res

if __name__ == '__main__':
    weight_list = [0.10,0.10,0.15,0.15,0.20,0.30]
    pa = OWAS()
    print(pa.getResult())